using System.Collections.Generic;
using UnityEngine;

namespace BCWAccountVip
{
	public class AccountVipWindow : MonoBehaviour
	{
		[SerializeField]
		private UILabel percentLabel;

		[SerializeField]
		private GameObject buttonExample;

		[SerializeField]
		private UIGrid grid;

		[SerializeField]
		private UILabel descriptionLabel;

		private bool _init;

		private string _description;

		public string Description
		{
			get
			{
				return _description;
			}
			set
			{
				_description = value;
				descriptionLabel.text = _description;
			}
		}

		private void Awake()
		{
			InAppShop.eventBuyAccount += HidePanelAccountVip;
		}

		private void OnDestroy()
		{
			InAppShop.eventBuyAccount -= HidePanelAccountVip;
		}

		private void Start()
		{
		}

		private void OnEnable()
		{
			if (!_init)
			{
				InitButtons();
			}
		}

		private void InitButtons()
		{
			foreach (KeyValuePair<string, ManagerVip.ConfigVip> configVip in ManagerVip.GetInstance().ConfigVips)
			{
				GameObject gameObject = Object.Instantiate(buttonExample);
				gameObject.transform.SetParent(grid.transform);
				gameObject.transform.localScale = Vector3.one;
				AccountVipButtonBuy component = gameObject.GetComponent<AccountVipButtonBuy>();
				component.KeyIAPs = configVip.Key;
				component.SetCountDay(configVip.Value.countDays);
				component.SetPrice(configVip.Key, configVip.Value.cost);
				gameObject.SetActive(true);
			}
			grid.repositionNow = true;
			_init = true;
		}

		private void HidePanelAccountVip()
		{
			base.gameObject.SetActive(false);
		}
	}
}
